Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
"Cannot read property of undefined."

I have some simple code that I've written in Python. It's working. Now I'm trying to port it to JavaScript. The code is here. I'm getting this error:

sketch.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'compression_ratio')
    at w (sketch.js:7:39)
    at ifsp (sketch.js:37:13)
    at draw (sketch.js:54:14)
    at p5._main.default.redraw (p5.js:71990:27)
    at _draw (p5.js:64140:25)

What's going wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The error is here (Starting line 28).

if (prob_sum > r) {
  attractor_index = j - 1;
} else {
  attractor_index = j;
}

If r is smaller than 1/3 (probability value that you have defined in line 51) you will decrement attractors_index using j - 1 and if that happens in the first iteration attractors_index will be -1 as j = 0. In that case attractors[attractors_index] will return undefined and you call w() with undefined instead of the object you expect, hence attractors.compression_ratio will not have a property compression_ratio and the error is thrown.

You can check/ reproduce that easily by manually setting r to > or < 1/3.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda